package xin.i18n.sample.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * <pre>
 *
 * </pre>
 *
 * @author lixin_ma@outlook.com
 * @since 2019/12/4
 */
@Controller
@RequestMapping
public class TestController {
	
	@Autowired
	private MessageSourceAccessor accessor;
	
	@RequestMapping
	@ResponseBody
	public Map<String, Object> test() {
		Map<String, Object> result = new HashMap<>();
		Locale locale = LocaleContextHolder.getLocale();
		System.out.println("test : " + locale.toString());
		result.put("login.fail.username", accessor.getMessage("login.fail.username"));
		result.put("login.fail", accessor.getMessage("login.fail"));
		result.put("login.success", accessor.getMessage("login.success"));
		return result;
	}
}
